<?php

namespace app\api\controller;

use app\admin\model\DormitoryBuilding;
use app\admin\model\DormitoryGarden;
use app\common\controller\Api;

/**
 * 楼栋接口
 */
class Building extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * @ApiTitle    (联动搜索 楼栋列表)
     * @ApiAuthor   (Zhenzh)
     * @ApiDateTime (2019/8/27 09:31)
     * @ApiSummary  ()
     * @ApiBody     ()
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/building/cxSelect)
     * @ApiHeaders  (name="token", type="string", required=true, description="请求的Token")
     * @ApiParams   (name="garden_id", type="int", required=true, description="园区id", sample="")
     * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码 1正常 0错误", sample="1")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回", sample="")
     * @ApiReturn ()
     */
    public function cxSelect()
    {
        $gender = $this->auth->gender;
        $garden_id = $this->request->request('garden_id');

        $result = DormitoryGarden::alias('garden')
            ->join('__DORMITORY_BUILDING__ building', 'garden.number = building.garden_number')
            ->where('garden.id', $garden_id)
            ->whereIn('building.dorm_type', [$gender, 3])
            ->field('building.id,building.number,building.name')
            ->select();

        $this->success('', $result);
    }

}
